/*
 * pusen_usb.cpp
 *
 *  Created on: May 22, 2019
 *      Author: wang
 */

#include <sys/statfs.h>
#include <stdio.h>

#include "pusen_usb.h"
int pusen_usb_get_space_info(char *path,pusen_usb *usb_info)
{
  int ret=0;
  struct statfs diskInfo;
  ret = statfs(path, &diskInfo);
  if(ret !=0){
      printf("statfs path:%s fail!ret=%d\n",path,ret);
      return ret;
  }
  unsigned long long blocksize = diskInfo.f_bsize; //每个block里包含的字节数
  unsigned long long totalsize = blocksize * diskInfo.f_blocks; //总的字节数，f_blocks为block的数目
  unsigned long long freeDisk = diskInfo.f_bfree * blocksize; //剩余空间的大小
  unsigned long long availableDisk = diskInfo.f_bavail * blocksize; //可用空间大小

  usb_info->available_size =availableDisk;
  usb_info->free_size=freeDisk;
  usb_info->totlal_size=totalsize;
  return 0;
}


